﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_AddJump]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_AddJump];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_AddJump]
    @FlowID int,
    @StepID int,
    @FieldName nvarchar(50),
    @Compare nvarchar(50),
    @CompareValue numeric(9,2),
    @ToStepID int,
    @FlowRule int = 0
AS
DECLARE @Priority INT
IF EXISTS(SELECT 1 
            FROM    
                uds_flow_jump
            WHERE flow_id = @FlowID and step_id = @stepid)
BEGIN
    SELECT @Priority = MAX(Priority) + 1
            FROM    
                uds_flow_jump
            WHERE flow_id = @FlowID and step_id = @stepid
END
ELSE
BEGIN
    SET @Priority = 1
END

INSERT INTO uds_flow_jump
    (priority,fieldname,compare,comparevalue,flow_id,step_id,to_step_id,Flow_Rule)
    VALUES(@Priority,@FieldName,@compare,@comparevalue,@flowid,@stepid,@ToStepID,@FlowRule)

    RETURN 0